<?php
/**
 * @author Nguyen Thanh Tung
 * @copyright 2014
 * @description: save action sample
 */
// not login
// not perm add
if( !isset($AppUI)||
!isset($_SESSION['personal'])||
isset($_SESSION['personal'])&& ($_SESSION['personal']&1<<1)==0)
{
	/*|| 
	(isset($AppUI->id) && !in_array($AppUI->type, array(ROLE_ROOT, ROLE_ADMINISTRATOR)))*/
	redirect(HOST_BACKEND);
}
// data input
$intPersonalId   = (int)$this->input->post('personalId',0);
$intClubId       = (int)$this->input->post('pclubid',0);			
$intLeagueId     = (int)$this->input->post('pleague',0); 
$intCategoryId   = (int)$this->input->post('pcategoryid',0);
$intSeasonId     = (int)$this->input->post('pseasons',0);
$arrErr          = array();
/*
// validate manual	
//+ Type	
if(!isset($inType) || empty($inType))
    array_push($arrErr, $arrLocale['select_type_required']);
//+ League	
if(!isset($intLeague) || empty($intLeague))
    array_push($arrErr, $arrLocale['select_league_required']);
//+ Categoryid	
if(!isset($intCategoryid) || empty($intCategoryid))
    array_push($arrErr, $arrLocale['select_category_required']);
//+ From	
if(!isset($intFrom) || empty($intFrom))
    array_push($arrErr, $arrLocale['select_form_required']);
//+ To	
if(!isset($intTo) || empty($intTo))
    array_push($arrErr, $arrLocale['select_to_required']);
//+ From < To	
if($intFrom >= $intTo)
    array_push($arrErr, $arrLocale['comparison']);

test(count($arrErr));*/

if(isset($arrErr) && count($arrErr)==0) {//allow save
    // unset session if exists
    if(isset($_SESSION['TITLE_ERROR'])) unset($_SESSION['TITLE_ERROR']);
    if(isset($_SESSION['TITLE_POST'])) unset($_SESSION['TITLE_POST']);
    $this->load->model('title_model', 'title');	
	
    $intError = $this->title->add($AppUI->id,$intPersonalId, $intClubId, $intLeagueId, $intCategoryId, $intSeasonId);
    if($intError==0) CI_Function::setMsg($arrMessage['save_add']);
    elseif($intError==1) array_push($arrErr, $arrLocale['noperm_save']);
}
// occur error

if (isset($arrErr) && count($arrErr) > 0) {
    $_SESSION['TITLE_ERROR']    = $arrErr;    
    $_SESSION['TITLE_ERROR']     = $this->input->post();
    
    redirect(HOST_BACKEND . 'title/add/'.$intPersonalId);
}
redirect(HOST_BACKEND.'index?persionalid='.$intPersonalId);
